package com.udl.emailfs.file;

import java.io.IOException;
import java.io.File;
import java.io.Serializable;

import com.udl.emailfs.system.SystemFS;

/**
 *
 * @author Edin Guermas Argiles
 */
// Clase que modela un descriptor de fichero del sistema de archivos
public class FileDescriptor implements Serializable {

	private static final long serialVersionUID = -3000351300773324289L;

	public String id;
    public String name;
    public long size;
    public String localpath;
    public String remotepath;
    public int positionR;
    public long positionW;
    public CNode cn;
    public String idnextBlock;
    public String idnextBlock2;
    public boolean blocked;
    public String nextAccount;
    public String nextAccount2;

    public void fileDescriptor(File f) throws IOException
    {
        if (f.exists() && f.canRead() && f.isFile())
        {
        id=SystemFS.getRandomID();
        localpath=f.getAbsolutePath();
        name=f.getName();
        size=f.length();
        remotepath="/";
        positionR=0;
        positionW=0;
        idnextBlock=SystemFS.getRandomID();
        idnextBlock2="";
        cn=new CNode();
        blocked=false;
        nextAccount="";
        nextAccount2="";
        }
        else
        {
            System.out.println("Error: Can't read or not exist file.");
        }
    }
}
